package views;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Container;
import java.awt.Dimension;
import java.util.Calendar;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
import java.util.Vector;

import javax.swing.CellEditor;
import javax.swing.JPanel;
import javax.swing.JButton;
import javax.swing.JScrollBar;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.ListSelectionModel;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableCellRenderer;
import javax.swing.table.TableColumn;

import com.sun.j3d.utils.geometry.Box;

import calendar_ex.Appointment;
import calendar_ex.CalendarDate;
import calendar_ex.CalendarEx;
import calendar_ex.CalendarTime;



public class DayView extends JPanel{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public DayView(){ 


		String[] headers = {"Time", "Event(s)",""};

		Object[][] rawData = new Object[24][2]; //N.B Object[i][1] will contain event descriptions
		for (int i = 0; i < 24; i++){
			rawData[i][0] = new CalendarTime(i,0);	
		}

		Object[][] displayData = new Object[24][2]; 
		for (int i = 0; i < 24; i++){
			displayData[i][0] = rawData[i][0].toString();	
		}

		CalendarEx calData = new CalendarEx();
		calData.openCalendar("calendar.txt");
		Calendar calendar = Calendar.getInstance();
		Date today = calendar.getTime();
		int dateDay = today.getDate();
		int dateMonth = today.getMonth();
		int dateYear = today.getYear();
		int hour = calendar.HOUR;

		CalendarDate start = new CalendarDate(4,11,2009);
		List<Appointment> daysAppointments;
		daysAppointments = calData.getAppointmentsBetweenDates(start,start);
		Iterator itApp = daysAppointments.iterator();
		while(itApp.hasNext()){
			Appointment temp = (Appointment) itApp.next();
			CalendarTime tempStartTime = temp.getStart_time();
			int tempStartHour = tempStartTime.hr;
			int appLasts = temp.getDuration();
			for(int i = 0; i < appLasts; i++){
				displayData[tempStartHour][1] = temp.description;
				tempStartHour++;
			}
		}

		DefaultTableModel dataModel = new DefaultTableModel(displayData, headers);

		//JTable table = new JTable(dataModel);


		JTable table = new JTable(dataModel); 
		table.setRowHeight(30);
		table.getColumnModel().getColumn(0).setPreferredWidth(50);
		table.getColumnModel().getColumn(1).setPreferredWidth(305);

		table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
		JScrollPane wvPanel = new JScrollPane(table);
		wvPanel.setPreferredSize(new Dimension(355,500));
		add(wvPanel);
	}

}


